package com.ruoyi.web.controller.deal;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deal.bo.HyDealOrderQueryBo;
import com.ruoyi.deal.domain.HyDealOrder;
import com.ruoyi.deal.service.IHyDealOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 交易订单Controller
 *
 * @author lixin
 * @date 2021-07-19
 */
@Api(value = "交易订单控制器", tags = {"交易订单管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/order/order")
public class HyDealOrderController extends BaseController {

    private final IHyDealOrderService iHyDealOrderService;

    /**
     * 查询交易订单列表
     */
    @ApiOperation("查询交易订单列表")
    @PreAuthorize("@ss.hasPermi('order:order:list')")
    @GetMapping("/list")
    public TableDataInfo<HyDealOrder> list(@Validated HyDealOrderQueryBo bo) {
        return iHyDealOrderService.queryPageList(bo);
    }

    /**
     * 获取交易订单详细信息
     */
    @ApiOperation("获取交易订单详细信息")
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping("/{orderId}")
    public AjaxResult<HyDealOrder> getInfo(@NotNull(message = "主键不能为空")
												 @PathVariable("orderId") Long orderId) {
        return AjaxResult.success(iHyDealOrderService.queryById(orderId));
    }

    /**
     * 新增交易订单
     */
    @ApiOperation("新增交易订单")
    @PreAuthorize("@ss.hasPermi('order:order:add')")
    @Log(title = "交易订单", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody HyDealOrder bo) {
        return toAjax(iHyDealOrderService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改交易订单
     */
    @ApiOperation("修改交易订单")
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "交易订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody HyDealOrder bo) {
        return toAjax(iHyDealOrderService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除交易订单
     */
    @ApiOperation("删除交易订单")
    @PreAuthorize("@ss.hasPermi('order:order:remove')")
    @Log(title = "交易订单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] orderIds) {
        return toAjax(iHyDealOrderService.deleteWithValidByIds(Arrays.asList(orderIds), true) ? 1 : 0);
    }
}
